home *** CD-ROM | disk | FTP | other *** search
- /*
- Bouncing bitmap
-
- This application will get a pixmap from its resource file. It will scale it to a smaller size.
- The pixmap (i.e. gBitmapShape) will then bounce around the window. We check to make sure the
- bitmapShape will be drawn within the bounds of the window by checking the location of the
- bitmapShape against the windowBoundsShape before each GXDrawShape call. The bitmapShape will be
- rotated 12 degrees before being drawn by GXDrawShape.
-
- NOTES:
- • This file requires the following files to run correctly:
- "graphics shell.c", "GraphicsDebugLibrary.c", "QDLibrary.c", "TransformLibrary.c".
-
- • For the best printing results, print this file in "landscape".
-
-
- Change History:
-
- 4/96 bob Updated #includes to support changed GX Library names.
- Changed fixed to Fixed.
- Updated the note regarding the files needed to run, and copyright date.
-
- ©1990 - 1996 Apple Computer, Inc.
- All rights reserved.
- */
-
-
- #include <Events.h>
- #include <Windows.h>
-
- #include "FontLibrary.h"
- #include <GXEnvironment.h>
- #include "GraphicsLibraries.h"
- #include <GXErrors.h>
- #include "QDLibrary.h"
- #include "graphics shell.h"
-
- //
- // Set up the title and size of the window
- //
- Rect gWindowQDRect = {40, 20, 340, 440};
- Str255 gWindowTitle = "\pBouncing bitmap";
-
- //
- // gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
- // in main () within graphics shell.c. You can determine the amount of graphics gxHeap required by using GraphicsBug.
- // With gGraphicsHeapSize set to 60k, I had 5 free blocks left in the graphics gxHeap. Sounds good to me.
- //
- long gGraphicsHeapSize = 80;
-
- gxShape gBitmapShape;
- gxRectangle gBitmapShapeBounds;
- Fixed gDx, gDy, gDelta;
- gxRectangle gFixedWindowBounds; // bounding box of the window in local coordinates
-
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
-
- void DoInitialization(theWindow)
- WindowPtr theWindow;
- {
- gxShape clipShape;
-
- //
- // Get the bounds of the window in GX coordinates. We will use this information in the
- // DoIdle function to make sure "Clarus" does not bounce outside of the window.
- //
- GXGetShapeBounds(gWindowBoundsShape, 0L, &gFixedWindowBounds);
-
- //
- // Get the pixmap from the a resource file. If we fail in our attempt to create gBitmapShape,
- // GXValidateShape will let us know via the debugger.
- //
- gBitmapShape = GetPixMapShape(128);
- GXValidateShape (gBitmapShape);
-
- GXScaleShape(gBitmapShape, fixed1/2, fixed1/2, 0, 0);
-
- GXGetShapeBounds(gBitmapShape, 0L, &gBitmapShapeBounds);
-
- //
- // Setup the clip gxShape of the gBitmapShape
- //
- clipShape = GXNewRectangle(&gBitmapShapeBounds);
- GXSetShapeClip(gBitmapShape, clipShape);
- GXDisposeShape(clipShape);
-
- gDx = ff(5) + fixed1/2;
- gDy = ff(6);
- }
-
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
-
- void DoIdle(theWindow)
- WindowPtr theWindow;
- {
- gxMapping map;
- gxShape boundsShape;
-
- GXRotateShape(gBitmapShape, ff(12), (gBitmapShapeBounds.left + gBitmapShapeBounds.right >> 1), (gBitmapShapeBounds.top + gBitmapShapeBounds.bottom >> 1));
-
- //
- // Get the bounds of the gBitmapShape and setup a gxRectangle that contains the bounds.
- //
- GXGetShapeBounds(gBitmapShape, 0L, &gBitmapShapeBounds);
- boundsShape = GXNewRectangle (&gBitmapShapeBounds);
-
- //
- // Get the gxMapping of the gBitmapShape and set boundsShape mapping to it. We use boundsShape
- // to setup the "new" "bounds" of our bouncing gBitmapShape. "bounds" is then used below to make
- // sure that "Clarus" does not bounce outside of the window.
- //
- GXGetShapeMapping(gBitmapShape, &map);
- GXMapShape(boundsShape, &map);
- GXGetShapeBounds(boundsShape, 0L, &gBitmapShapeBounds);
-
- //
- // Make sure "Marilyn" doe not bounce outside of the window, by adjusting the "new" location
- // appropriately.
- //
- if ((gDelta = gFixedWindowBounds.left - gBitmapShapeBounds.left) > 0 || (gDelta = gFixedWindowBounds.right - gBitmapShapeBounds.right) < 0)
- {
- GXMoveShape(gBitmapShape, gDx + gDelta, ff(0));
- gDx = -gDx;
- }
-
-
- if ((gDelta = gFixedWindowBounds.top - gBitmapShapeBounds.top) > 0 || (gDelta = gFixedWindowBounds.bottom - gBitmapShapeBounds.bottom) < 0)
- {
- GXMoveShape(gBitmapShape, ff(0), gDy + gDelta);
- gDy = -gDy;
- }
-
- GXMoveShape(gBitmapShape, gDx, gDy);
- GXDrawShape(gBitmapShape);
-
- GXDisposeShape(boundsShape);
- }
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
-
- void DoDraw(theWindow)
- WindowPtr theWindow;
- {
- GXDrawShape(gBitmapShape);
- }
-
-
-
-
- /*------ DoDispose ------------------------------------------------------------------------------------*/
-
- void DoDispose(theWindow)
- WindowPtr theWindow;
- {
- //
- // You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- // form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- // call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- // SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- // can turn notices on in this file by setting gDebugging = TRUE (above).
- //
- GXDisposeShape(gBitmapShape);
- GXDisposeShape(gWindowBoundsShape);
- DisposeWindow(theWindow);
- }
-
-
-
- /*------ DoClick ---------------------------------------------------------------------------------------*/
-
- void DoClick( orgMouseLoc, theWindow )
- gxPoint orgMouseLoc;
- WindowPtr theWindow;
- {
- }
-
-